/**   
 * Copyright © 2016 公司名. All rights reserved.
 * 
 * @Title: UserLoginLogRestController.java 
 * @Prject: LianniuManager
 * @Package: com.lianniu.mgr.baseService.userLog.controller
 * @Description: TODO
 * @author: lzz   
 * @date: 2016年8月4日 下午3:21:23 
 * @version: V1.0   
 */
package com.lianniu.mgr.baseService.userLoginLog.controller;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.userLoginLog.model.UserLoginLogVo;
import com.lianniu.mgr.baseService.userLoginLog.service.IUserLoginLogService;
import com.lianniu.mgr.pagination.PaginationInfo;

/** 
 * @ClassName: UserLoginLogRestController 
 * @Description: TODO
 * @author: lzz
 * @date: 2016年8月4日 下午3:21:23  
 */
@Controller
public class UserLoginLogRestController {
    
    private final static Logger logger = Logger.getLogger(UserLoginLogRestController.class);
    
    @Resource
    private IUserLoginLogService userLoginLogService;
    
    @RequestMapping(value = "/rest/userLoginLogList", method = {RequestMethod.GET})
    public @ResponseBody BaseResult userLoginLogList(HttpServletRequest request, UserLoginLogVo userLoginLogVo,
        PaginationInfo paginationInfo) {
      logger.info("UserLoginLogRestController userLoginLogList begin");
      logger.info("UserLoginLogRestController userLoginLogList LogVo:" + JSON.toJSONString(userLoginLogVo));
      Date endTime = userLoginLogVo.getEndTime();
      if (endTime != null) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(endTime);
        calendar.add(Calendar.DATE, 1);// 把日期往后增加一天.整数往后推,负数往前移动
        endTime = calendar.getTime(); // 这个时间就是日期往后推一天的结果
        userLoginLogVo.setEndTime(endTime);
      }
      try {
        logger.info("userLoginLogList getUserLoginLogList start");
        BaseResult baseResult = userLoginLogService.getUserLoginLogList(userLoginLogVo, paginationInfo);
        logger.info("getUserLoginLogList baseResult:" + JSON.toJSONString(baseResult));
        logger.info("userLoginLogList getUserLoginLogList end");
        return baseResult;
      } catch (Exception e) {
        logger.error("UserLoginLogRestController userLoginLogList error:" + e.getMessage());
        logger.info("UserLoginLogRestController userLoginLogList end");
        return BaseResult.success();
      }
    }
}
